import { NestFactory } from '@nestjs/core';
import { AppModule } from './modules/app/app.module';
import { MicroserviceOptions, Transport } from '@nestjs/microservices';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { ResponseInterceptor } from './interceptors/response/response.interceptor';
import { KnowledgeTransformInterceptor } from './interceptors/knowledge-transform/knowledge-transform.interceptor';
import { NestExpressApplication } from '@nestjs/platform-express';
import { join } from 'path';
async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);
  app.enableCors();
  app.setGlobalPrefix('api');
  app.useGlobalInterceptors(new ResponseInterceptor(),new KnowledgeTransformInterceptor())

  const config = new DocumentBuilder()
    .setTitle('API Title')
    .setDescription('API Description')
    .setVersion('1.0')
    .addTag('AI') // Optional: Add tags for grouping
    .addBearerAuth() // Add authentication if needed
    .build();
      // 配置上传文件夹作为静态资源目录，添加.d.ts文件的MIME类型
  app.useStaticAssets(join(__dirname, '..', 'uploads'), {
    prefix: '/uploads/',
    setHeaders: (res, path) => {
      if (path.endsWith('.d.ts')) {
        res.set('Content-Type', 'text/plain; charset=utf-8');
      }
    }
  });
  
  const document = SwaggerModule.createDocument(app, config);
  SwaggerModule.setup('doc', app, document); // 'api' is the endpoint path

  await app.startAllMicroservices();
  await app.listen(process.env.PORT ?? 9090);
}
bootstrap();
